package gateway

type CommonResp struct {
	Code      ErrorCode `json:"code"`
	Data      any       `json:"data"`
	ErrorInfo string    `json:"error_info"`
}

func NewResponse(data any, err error, explicitCode ErrorCode) *CommonResp {
	code := Ok
	if explicitCode != code {
		code = explicitCode
	} else if err != nil {
		code = InnerError
	}

	if err != nil {
		return &CommonResp{
			Code:      code,
			ErrorInfo: err.Error(),
		}
	}
	return &CommonResp{
		Code:      code,
		Data:      data,
		ErrorInfo: "success",
	}
}
